Implements prototype of hydra_zen.like #219
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potentially addresses: #205
#219 prototypes a potential solution to the above, that is much more powerful than what I had initially proposed. This is inspired by @jgbos ' out of left field idea 😄
Let's see
hydra_zen.like
in action:what is going on here?
hydra_zen.like(<target>)
returns a_Tracker
instance that records all subsequent interactions with<target>
. Right now, "interactions" are restricted to accessing attributes and calling the target.hydra_zen.just
then knows how to convert a_Tracker
instance into a valid Hydra config.Let's use this to make a config that actually returns the
manual_seed
method of our Generator-instance:Here is a silly example, just to help give more of a feel for this:
Current thoughts on this prototype
One nice thing about
like
is that looks like a simple pass-through to IDEs, so you get auto-completes, static type checks, etc. as you build your "like expression" prior to creating the config.Some obvious to-dos would include:
GenLike().manual_seedling(42)
should raise a runtime error becausemanual_seedling
is not an attribute ofGenerator
.just(like(<...>).<...>)
expression as clean as possiblejust(like(<target>)(*args, **kwargs))
should reduce down tobuilds(<target>, *args, **kwargs)
like
'd objects in their configs without them needing to calljust
first.I would definitely like to get feedback on this. I only just thought of it, and will have to think carefully about potential pitfalls as well as about possible use cases that I haven't anticipated yet.
Additional functionality
like
could also fulfill the role of the proposedhydra_zen.hydrate